package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.Movie;
import pojo.Video;

import dao.MovieHome;
import dao.StoptimeHome;
import dao.TrailerHome;
import dao.VideoHome;

import service.IMovieService;
import service.IVideoService;
import serviceImp.MovieServiceImp;
import serviceImp.VideoService;

/**
 * Servlet implementation class MovieServlet
 */
public class VideoServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    private IVideoService videoServiceImp;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public VideoServlet() {
	super();
	// TODO Auto-generated constructor stub

	VideoService imp = new VideoService();
	
	imp.setVideoDao(new VideoHome());
	imp.setTrailerDAO(new TrailerHome());
	imp.setStoptimeDAO(new StoptimeHome());

	videoServiceImp = imp;

    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {

	String vid = request.getParameter("vid");
	Video video;

	// check the vid is valid
	if (vid == null) {
	    response.sendError(1);
	}
	
	video = videoServiceImp.getVideoById(Integer.valueOf(vid));

	request.setAttribute("video", video);

	request.getRequestDispatcher("video.jsp").forward(request, response);

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
	    HttpServletResponse response) throws ServletException, IOException {
	doGet(request, response);
    }

}
